//
//  AgreementViewController.swift
//  FeastBooking
//
//  Created by Imon on 2017/12/10.
//  Copyright © 2017年 Imon. All rights reserved.
//

import UIKit

class AgreementViewController: UIViewController {

    var scrollView: UIScrollView?
    
    let agreementLabel: UILabel = {
        let label = UILabel()
        label.font = AppFont(size: 12)
        label.numberOfLines = 0
        label.textColor = UIColor.black
        return label
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationItem.title = LanguageHelper.getString(key: "AGREEMENT")
        
        let leftBt = UIButton()
        leftBt.contentHorizontalAlignment = .left
        leftBt.setImage(UIImage(named: "cross"), for: .normal)
        leftBt.tintColor = UIColor.black
        leftBt.addTarget(self, action: #selector(close(_:)), for: .touchUpInside)
        leftBt.sizeToFit()
        self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: leftBt)
        
        scrollView = UIScrollView()
        scrollView?.frame = self.view.bounds
        scrollView?.showsVerticalScrollIndicator = true
        scrollView?.showsHorizontalScrollIndicator = false
        scrollView?.isScrollEnabled = true
        scrollView?.alwaysBounceVertical = true
        scrollView?.autoresizingMask = UIViewAutoresizing.flexibleHeight
        
        agreementLabel.text = agreementContent
        let textMaxSize = CGSize(width: self.view.bounds.width - 20, height: 1/0.0)
        let agreementSize = TextSize.textSize(text: agreementLabel.text!, font: agreementLabel.font, maxSize: textMaxSize)
        agreementLabel.frame = CGRect(x: 10, y: 10, width: agreementSize.width, height: agreementSize.height)
        scrollView?.addSubview(agreementLabel)
        
        scrollView?.contentSize = CGSize(width: self.view.bounds.width, height: agreementLabel.frame.origin.y + agreementLabel.frame.height)
        
        self.view.addSubview(scrollView!)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func close(_ sender: UIBarButtonItem) {
        self.dismiss(animated: true, completion: nil)
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
